function [hdr,vol] = spline_smooth(imageFileName, maskFileName,outputDir, splineDistanceRange,lambdaRange)
%SPLINE_SMOOTH Spline filters a Minc image, outputs the header and volume.
%   
%   SYSTEM PREREQUISITES: Minc Tools, spline_smooth version 1.12, NIAK.
%
%   ***********************************************************************
%
%   INPUT PARAMETERS:
%
%   imageFileName: String of Minc file containing image to be smoothed.
%
%   maskFileName: String of Minc file containing mask.
%
%   outputDir: Output directory string where smoothed image (Minc format)
%   will be stored.
%
%   splineDistanceRange: Distance between basis functions in mm.  This 
%   parameter determines the overall smoothness. CAN BE A VECTOR.
%
%   lambdaRange: Scale invariant smoothing parameter. CAN BE A VECTOR.
%   ***********************************************************************
%
%   Author: Mathieu Boudreau (mboudrea2@mail.mcgill.ca)
%   Institute: McConnell Brain Imaging Center, Montreal Neurological 
%              Institute, Montreal, Quebec, Canada.
%   Date: March 21 2014
%
%   Last modified on: March 21 2014
%   Last modified by: Mathieu Boudreau
%

    %% Make directories
    %
    
    mkdir(outputDir)
    
    %% Call Spline Smooth
    %
    
    for splineDistanceIndex = 1:length(splineDistanceRange)
        for lambdaIndex = 1:length(lambdaRange)
            system(['spline_smooth -verbose -distance ' num2str(splineDistanceRange(splineDistanceIndex)) ' -lambda ' num2str(lambdaRange(lambdaIndex)) ' -mask '  maskFileName ' ' imageFileName ' ' outputDir '/b1_spline_SplineDist_'  num2str(splineDistanceRange(splineDistanceIndex)) '_lambdaRange_' num2str(lambdaRange(lambdaIndex)) '.mnc']);        
        end
    end
    
    %% Load smoothed image to Matlab
    %
    
    for splineDistanceIndex = 1:length(splineDistanceRange)
        for lambdaIndex = 1:length(lambdaRange)
            [hdr{splineDistanceIndex,lambdaIndex},vol{splineDistanceIndex,lambdaIndex}]=niak_read_minc([outputDir '/b1_spline_SplineDist_'  num2str(splineDistanceRange(splineDistanceIndex)) '_lambdaRange_' num2str(lambdaRange(lambdaIndex)) '.mnc']);        
        end
    end
        

end

